import { Injectable, resolveForwardRef } from '@angular/core';
import {HttpClient} from '@angular/common/http'

@Injectable({
  providedIn: 'root'
})
export class SvjackService {

  constructor(
    private http:HttpClient
  ) { }
  urlMapping = [{
    name:'test',
    url:'/api',
    desc:'this is test proxy and other'
  }]
  apiRequest(name){
    let urlitem = this.urlMapping.filter(item => {
      if(item.name == name) {
        return true
      }
    })[0]
    if(urlitem) {
      let url = `${urlitem.url}`
      return this.http.get(url).toPromise()
    } else {
      return  Promise.reject(`can not find request name [[${name}]]`)
    }
  }
}

export class Messge<T> {
  sucess:boolean;
  msg?:string;
  data?:T;
  errcode:string;
  timestamp: number;
}